#
# This file is a part of the open-eBackup project.
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at
# http://mozilla.org/MPL/2.0/.
#
# Copyright (c) [2024] Huawei Technologies Co.,Ltd.
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
#

from common.parse_parafile import ParamFileUtil
from exchange.commons.const import ExchangeJobInfo
from exchange.commons.exchange_function_tool import log_start_end, out_result_with_job_info
from exchange.commons.exchange_param_parse import ExchangeParamParse


# Exchange检查是否可在本地执行基类
class ExchangeBackupAllowBackupInLocalNode:
    def __init__(self, pid):
        self._pid = pid
        self._param = ParamFileUtil.parse_param_file(pid)

    @log_start_end()
    @out_result_with_job_info()
    def do_allow_backup_in_local_node_task(self, job_info: ExchangeJobInfo):
        # 无校验，直接返回成功
        return True

    def get_job_info(self):
        job_info = ExchangeJobInfo(pid=self._pid,
                                   job_id=ExchangeParamParse.get_job_id(self._param),
                                   sub_job_id=ExchangeParamParse.get_sub_job_id(self._param),
                                   copy_id=ExchangeParamParse.get_copy_id(self._param),
                                   backup_type=ExchangeParamParse.get_type(self._param))
        return job_info